package workflow.action;

import java.util.List;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springside.core.web.StrutsEntityAction;
import org.apache.struts.validator.LazyValidatorForm;

import workflow.dao.ProcessTransitionDao;
import workflow.model.ProcessTransition;

import common.Globals;
import common.PageInfo;

public class ProcessTransitionAction extends StrutsEntityAction<ProcessTransition, ProcessTransitionDao> {
	private ProcessTransitionDao processTransitionManager;
	
	public ProcessTransitionDao getProcessTransitionManagerr() {
		return processTransitionManager;
	}

	public void setProcessTransitionManager(ProcessTransitionDao ProcessTransitionManager) {
		this.processTransitionManager = ProcessTransitionManager;
	}
	
	/**
	 *列表
	 */
	@Override
	public ActionForward list(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		LazyValidatorForm lvForm = (LazyValidatorForm)form;
		PageInfo pageInfo = new PageInfo(request);
		HashMap<String, String> hm = new HashMap<String, String>();
		//TODO 组装查询条件
		
		String id = (String)lvForm.get("s_id");
		hm.put("id" ,id);
		String name = (String)lvForm.get("s_name");
		hm.put("name" ,name);
		String proInsId = (String)lvForm.get("s_proInsId");
		hm.put("proInsId" ,proInsId);
		String startTaskFlag = (String)lvForm.get("s_startTaskFlag");
		hm.put("startTaskFlag" ,startTaskFlag);
		String endTaskFlag = (String)lvForm.get("s_endTaskFlag");
		hm.put("endTaskFlag" ,endTaskFlag);
		String status = (String)lvForm.get("s_status");
		hm.put("status" ,status);

				
		List<ProcessTransition> poList = this.processTransitionManager.findList(hm, pageInfo);
		request.setAttribute("list", poList);
		
		return mapping.findForward(Globals.FORWARD_LIST);
	}
	
	/**
	 * 删除
	 */
	@Override
	public ActionForward delete(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		super.delete(mapping, form, request, response);
		
		return this.list(mapping, form, request, response);
	}

	/**
	 * 保存
	 */
	@Override
	public ActionForward save(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {		
		super.save(mapping, form, request, response);
		
		return this.list(mapping, form, request, response);
	}
	
	/**
	 * 该方法被delete方法调用
	 */
	@Override
	protected void doDeleteEntity(ActionForm form, HttpServletRequest request) {
		String ids = request.getParameter("ids");
		try {
			if (ids != null && !"".equals(ids.trim())) {
				getEntityManager().deleteByIds(ids);
				// TODO 修改操作事件，参考logWrite方法要求
				//logsManager.logWrite(request, "", "操作日志", 0);
			}
		} catch (Exception e) {
			// TODO 修改操作事件，参考logWrite方法要求
			//logsManager.logWrite(request, "", "操作日志", 0);
		}
	}
}


